/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * busquedaDoctor.java
 *
 * Created on 24-nov-2010, 18:39:07
 */

package GUI.clinica;
import GUI.clinica.clinica;
import javax.swing.JOptionPane;
import cprincipal.*;
import Persistencia.*;
import venehealthfinal.Validar;

/**
 *
 * @author RafaelGutierrez
 */
public class busquedaDoctor extends javax.swing.JFrame {

    /** Creates new form busquedaDoctor */

    private boolean resultado = false;
    DoctorXml datosDoct=new DoctorXml();


    public busquedaDoctor() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        BotonRegresar = new javax.swing.JButton();
        BotonBuscar = new javax.swing.JButton();
        LabelCedulaDoctor = new javax.swing.JLabel();
        TxtCedula = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        BotonAgregar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        BotonRegresar.setText("Regresar ");
        BotonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonRegresarActionPerformed(evt);
            }
        });

        BotonBuscar.setText("Buscar");
        BotonBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonBuscarActionPerformed(evt);
            }
        });

        LabelCedulaDoctor.setFont(new java.awt.Font("Tahoma", 0, 12));
        LabelCedulaDoctor.setText("Cedula de Doctor:");

        TxtCedula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TxtCedulaActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jLabel1.setText("Busqueda de Doctor");

        BotonAgregar.setText("Nuevo");
        BotonAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonAgregarActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(layout.createSequentialGroup()
                        .add(93, 93, 93)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(BotonAgregar)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(BotonBuscar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 79, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(BotonRegresar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 91, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(LabelCedulaDoctor)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(TxtCedula, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 124, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(28, 28, 28))))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(jLabel1)
                        .add(63, 63, 63)))
                .add(128, 128, 128))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(TxtCedula, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(LabelCedulaDoctor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 17, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(123, Short.MAX_VALUE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(129, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(BotonRegresar)
                    .add(BotonBuscar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(BotonAgregar))
                .add(37, 37, 37))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BotonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonRegresarActionPerformed
        clinica ventana =  new clinica();
        ventana.setVisible(true);
        this.dispose();
}//GEN-LAST:event_BotonRegresarActionPerformed

    private void BotonBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonBuscarActionPerformed
         if (TxtCedula.getText().isEmpty()){ /*&& (!TxtNombre.getText().isEmpty()) && (!TxtApellido.getText().isEmpty()) && (!TxtAnioNac.getText().isEmpty()) && (!TxtLocalidad.getText().isEmpty()) && (!TxtNumeroColegiatura.getText().isEmpty()) && (!TxtUniversidadEgreso.getText().isEmpty()) && (!TxtEstudiosEspeciales.getText().isEmpty()) && (!TxtEspecialidad.getText().isEmpty()) && (!TxtDisponibilidad.getText().isEmpty()) && (!TxtHoraEntrada.getText().isEmpty()) && (!TxtHoraSalida.getText().isEmpty())*/
            JOptionPane.showMessageDialog(null, "Error, campo invalidos", "Debe indicar un numero de cedula valido", JOptionPane.ERROR_MESSAGE);
        } else {
            System.out.println("no ha entrado en validar");
             //int valor = Validar.ValidarEntero(TxtCedula.getText(), "Cédula no es numérica");
            //if (valor == 1) {
               Doctor doct = datosDoct.buscarDoctor(Integer.parseInt(TxtCedula.getText()));
                if (doct == null) {
                  JOptionPane.showMessageDialog(null, "Doctor no Existe", "Error cédula no encontrada", JOptionPane.ERROR_MESSAGE);
                } else {

                    informacionDoctor ventana =  new informacionDoctor(doct);
                    ventana.setVisible(true);
                    this.dispose();
                }
        
        }


        
}//GEN-LAST:event_BotonBuscarActionPerformed

    private void TxtCedulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TxtCedulaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_TxtCedulaActionPerformed

    private void BotonAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonAgregarActionPerformed
        // TODO add your handling code here:
          if (TxtCedula.getText().isEmpty()){
              JOptionPane.showMessageDialog(null, "Error, campo invalidos", "Debe indicar un numero de cedula valido", JOptionPane.ERROR_MESSAGE);
        } else {
            System.out.println("Antes de validar");
            int valor = Validar.ValidarEntero(TxtCedula.getText(), "Cédula no es numérica");
            System.out.println("Despues de validar");
            if (valor == 1) {
               System.out.println("Entro en el ciclo");
               Doctor doct = new Doctor();
                    doct.setCedula(Integer.parseInt(TxtCedula.getText()));
                    System.out.println("antes de ventana");
                    informacionDoctor ventana =  new informacionDoctor(doct);
                    ventana.setVisible(true);
                    this.dispose();
                }
        }
    }//GEN-LAST:event_BotonAgregarActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new busquedaDoctor().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotonAgregar;
    private javax.swing.JButton BotonBuscar;
    private javax.swing.JButton BotonRegresar;
    private javax.swing.JLabel LabelCedulaDoctor;
    private javax.swing.JTextField TxtCedula;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables

}
